package cn.itsy.service.user;

import cn.itsy.dao.user.UserDao;
import cn.itsy.pojo.EmpAndUserAndRole;
import cn.itsy.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-06-03 17:05
 */
@Service(value = "userServiceimpl")
public class UserServiceimpl implements UserService {
    @Resource(name = "userDaoimpl")
    private UserDao userDao;

    @Override
    public List<User> queryUserAll(String sql) {
        return this.userDao.queryUserAll(sql);
    }

    @Override
    public List<EmpAndUserAndRole> queryEmpAndUserAndRole(String sql) {
        List<EmpAndUserAndRole> empAndUserAndRoles = this.userDao.queryEmpAndUserAndRole(sql);
        return empAndUserAndRoles;
    }

    @Override
    public void saveUser(String sql, User user) {
        this.userDao.saveUser(sql, user);
    }

    @Override
    public User queryUserLastId(String sql) {
        List<User> users = this.userDao.queryUserLastId(sql);
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public void updatUserByuName(String sql, String uname, String oldUname) {
        this.userDao.updatUserByuName(sql, uname, oldUname);
    }

    @Override
    public User queryUserByuName(String sql, String uname) {
        List<User> users = this.userDao.queryUserByuName(sql, uname);
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public void deleteUserByuName(String sql, String uname) {
        this.userDao.deleteUserByuName(sql, uname);
    }
}
